package servlet;

import java.sql.*;
import java.util.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ManageUserServlet
 */
public class ManageUserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
	Connection conn=null;
	Statement stmt=null;
	ResultSet rs=null;
	PrintWriter out;
	List userData=new ArrayList();
	String query="select * from login";
	String url="ManageUsers.jsp";
    String url1="http://localhost:8181/PropertySite/ManageUsers.jsp";
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		response.setContentType("text/html");
	   // response.setHeader("Refresh","1");
		out=response.getWriter();
		out.println(query);
		
		try
		{
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			conn=DriverManager.getConnection("Jdbc:Odbc:siteDSN","scott","tiger");
			stmt=conn.createStatement();
			stmt.executeQuery(query);
			rs=stmt.getResultSet();
			

			
			while(rs.next())
			{
				userData.add(rs.getString(1));
				//userData.add(rs.getString(2));
			}
			
			 request.setAttribute("userdata",userData);

			RequestDispatcher reqDispatcher=request.getRequestDispatcher(url);
			if(reqDispatcher!=null)
			{
				reqDispatcher.forward(request, response);
			}
			rs.close();
			stmt.close();
			conn.close();
		}

		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
	    
		

	}

}
